<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\admin\model\UserTable;
use app\admin\validate\Certification as CertificationValidate;
class Certification extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    /**
     * 实名认证显示
     *
     */
    public function index()
    {
        $user = UserTable::field('id,real_name,mobile,idcard')->find($this->auth->id);
        if (empty($user['idcard']) || empty($user['real_name'])){
            $user->is_real = 0;
        }else{
            $user->is_real = 1;
        }
        $this->success('获取成功',$user);
    }

    /**
     * 实名认证
     *
     */
    public function check()
    {
        $user = UserTable::field('id,real_name,mobile,idcard')->find($this->auth->id);
        if (empty($user['idcard']) && empty($user['real_name'])){
            $data = $this->request->post();
//            $validate = new CertificationValidate();
//            if (!$validate->scene('check')->check($data)) {
//                $this->error($validate->getError());
//            }
            if (empty($data['real_name'])){
                $this->error('请输入姓名');
            }
            if (empty($data['mobile'])){
                $this->error('请输入手机号');
            }
            if (empty($data['idcard'])){
                $this->error('请输入身份证号');
            }
            $user->save($data);
            $this->success('实名成功',$user);
        }
        $this->success('获取成功',$user);
    }
}